package deatax;


import deatax.network.Client;
import deatax.network.Messages;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author pson
 */
public class PlayerRoster {
    
    private ArrayList<Player> players;
    private Player current_player;
    private int current_index;
    private ArrayList<Player> losers;

    public PlayerRoster() {
        players = new ArrayList<Player>();
        current_player = null;
        current_index = 0;
        losers = new ArrayList<Player>();
    }
    
    public void addPlayer(Player p) {
        if (players.isEmpty()) {
            current_player = p;
        }
        players.add(p);
    }
    
    public void losePlayer(Player p) {
        int i = 0;
        for (Player pl : players) {
            if (pl == p) {
                if (i <= current_index) {
                    current_index--;
                }
            }
            ++i;
        }
        players.remove(p);
        losers.add(p);
    }
    
    public Player getCurrentPlayer() {
        return current_player;
    }

    public ArrayList<Player> getLosers() {
        return losers;
    }
    
    public void nextPlayer() {
        current_index++;
        if (current_index == players.size()) {
            current_index = 0;
        }
        current_player = players.get(current_index);
    }

    public ArrayList<Player> getPlayers() {
        return players;
    }

    public Player getPlayer(String player) {
        for (Player p : players) {
            if (p.getName().equals(player)) {
                return p;
            }
        }
        for (Player p : losers) {
            if (p.getName().equals(player)) {
                return p;
            }
        }
        return null;
    }

    
    
}
